﻿var app = Vue.createApp({
    data() {
        return {
            title: "Single Sugar 1.0",
            loading: false,
            model: {
                username: "admin",
                password: "a123456"
            },
            rules: {
                username: [{ required: true, message: "请输入用户名" }],
                password: [{ required: true, message: "请输入密码" }]
            }
        };
    },
    methods: {
        init() {
            $(".work-init-loading").fadeOut();
        },
        reset() {
            this.model.username = "";
            this.model.password = "";
        },
        login() {
            var that = this;
            that.$refs.formRef.validate(valid => {
                if (valid && !that.loading) {
                    $.ajax({
                        url: "/work/home/login",
                        type: "post",
                        data: that.model,
                        dataType: "json",
                        beforeSend() {
                            that.loading = true;
                        },
                        complete() {
                            that.loading = false;
                        },
                        success(result) {
                            if (result.success) {
                                that.$message({ message: result.message, type: "success" });
                                location.replace("/work/home/index");
                            }
                            else {
                                that.$message({ message: result.message, type: "warning" });
                            }
                        },
                        error(request) { console.info(request); }
                    });
                }
            });
        }
    },
    mounted() { this.init(); }
});
registerComps(app, ElementPlusIconsVue);
app.use(ElementPlus, { locale: ElementPlusLocaleZhCn });
app.mount("#app");